<template>
	<view>
		<view class="herder">
			<u-steps :current="current" activeIcon="checkmark-circle" inactiveIcon="clock-fill">
				<!-- <u-steps-item title="风险措施确认"></u-steps-item>
				<u-steps-item title="操作"></u-steps-item> -->
				<!-- <u-steps-item title="完成"></u-steps-item> -->
				<u-steps-item title="操作票详情" @click.native="navs(0)"></u-steps-item>
				<u-steps-item title="风险措施确认" @click.native="navs(1)"></u-steps-item>
				<u-steps-item title="操作" @click.native="navs(2)"></u-steps-item>
			</u-steps>
		</view>
		<detailsMap v-if="current == 0 " :form="datas" :key="new Date().getTime()" @nuxt="nuxt"></detailsMap>
		<riskEdit v-if="current ==1" :listRisk="listRisk" :obj="datas" @nuxt="nuxt"></riskEdit>
		<operateEdit v-if="current ==2" :listProcess="listProcess" :obj="datas" @nuxt="nuxt">
		</operateEdit>
	</view>
</template>

<script>
	import urlConfig from "@/request/urlConfig.js";
	import {
		getInfo
	} from '@/api/risks.js'
	import riskEdit from '../../components/execute/riskEdit.vue'
	import operateEdit from '../../components/execute/operateEdit.vue'
	import detailsMap from '../../components/execute/details.vue'
	export default {
		components: {
			riskEdit,
			operateEdit,
			detailsMap
		},
		data() {
			return {
				current: 0,
				listRisk: [],
				listProcess: [],
				datas: {}
			};
		},
		watch: {
			current: function(newVal, oldVal) {
				if (newVal == 0) {
					uni.setNavigationBarTitle({
						title: '风险措施确认'
					})
				} else {
					uni.setNavigationBarTitle({
						title: '操作流程'
					})
				}
			}
		},
		onLoad(option) {
			this.getInit(option.id)
		},
		methods: {
			navs(e) {
				this.current = e
			},
			nuxt(e) {
				this.current = e
			},
			async getInit(id) {
				const res = await getInfo({
					id: id
				})
				console.log(res, 'res');
				this.datas = res.datas
				res.datas.listRisk.forEach((v, i) => {
					v.types = v.state == 1 ? 1 : '',
						v.file = v.fileUrl ? v.fileUrl.split(',').map(vs => {
							return {
								url: urlConfig.nearbyUrl + vs,
								urlTow: vs
							};
						}) : [];
				})
				res.datas.listProcess.forEach(v => {
					v.answer = v.submitContent ? v.submitContent.split(',').map(vs => {
						return {
							value: vs
						};
					}) : [];

					v.file = v.fileUrl ? v.fileUrl.split(',').map(vs => {
						return {
							url: urlConfig.nearbyUrl + vs,
							urlTow: vs
						};
					}) : [];

					v.shopList = v.content.split(',').map(vi => {
						if (v.category == 1) {
							v.answer.push({
								value: ''
							})
						}
						return {
							value: vi
						}
					})
					if (v.category == 1) {

						let count = this.countParentheses(v.name)
						let inputlist = v.name.split('()').filter(Boolean)
						let inputTxt = inputlist.slice(count).join('')
						inputlist.splice(count)
						console.log(inputlist, "inputlist");
						console.log(count, "count");
						console.log(inputTxt, "inputTxt");
						v.inputList = inputlist
						v.inputTxt = inputTxt
					}
				})
				this.listRisk = [...res.datas.listRisk]
				console.log(this.listRisk, "this.listRisk ");
				this.listProcess = [...res.datas.listProcess]
			},
			countParentheses(str) {
				const regex = /\(\)/g;
				const matches = str.match(regex)
				console.log(matches, 'matches')
				return matches ? matches.length : 0
			},
		}
	}
</script>

<style>
	page {
		background-color: #F5F5F5;
		padding-bottom: 40rpx;
	}
</style>
<style lang="scss" scoped>
	.herder {
		height: 170rpx;
		background: #FFFFFF;
		padding-top: 46rpx;
	}
</style>